<?
//impostazioni modulo Utente
include("includes/config.inc.php");
include("includes/auth.lib.php");
include("includes/user.class.php");
$module = "UTENTE";
   list($status, $user) = auth_get_status();
   switch($status){
       case AUTH_LOGGED:
	    $menusx = '<table widht="100%" cellpadding="2">
	    <tr>
	    <td valign=middle width=30 height=30><a class=menusx href="user.php?op=all"><img src="imgs/ico_list.gif" width=30 height=30 alt="" border=0></a></td><td align=left valign=middle><a class=menusx href="user.php?op=all">Elenco utenti Bsvillage</a>
	    </td>
	    </tr>
	    <tr>
	    <td valign=middle width=30 height=30><a class=menusx href="user.php?op=add"><img src="imgs/ico_list.gif" width=30 height=30 alt="" border=0></a></td><td align=left valign=middle><a class=menusx href="user.php?op=add">Aggiungi utente Bsvillage</a>
	    </td>
	    </tr>
	    <tr>
	    <td valign=middle width=30 height=30><a class=menusx href=gestione.php><img src="imgs/ico_back.gif" width=30 height=30 alt=Principale border=0></a></td><td align=left valign=middle><a class=menusx href=gestione.php>Torna alla pagina principale</a>
	    </td>
	    </tr>
	   </table>';
            $result1 = @mysql_query("SELECT nome,stato FROM utenti WHERE id='$id_user';");
            list($username,$level) = mysql_fetch_row($result1);
	if($level == "admin")  {
		//recupero i dati in POST
		$usernamep = $_POST['username'];
		$passwordp = $_POST['password'];
		$nomep = $_POST['nome'];
		$statop = $_POST['stato'];
			$op = $_GET['op'];
			if(!isset($op) || $op == "")
			 $op = $_POST['op'];
		switch($op)  {
			
		  case "all":
		  	$qry = "SELECT id,nome,stato FROM utenti;";
		  	$rs = $conn->Execute($qry);
		  	$content = '<table class="content" width="400" align="center" cellpadding="3" cellspacing="0">
		  					<tr>
		  						<td class="tbtit" width="200">Nome</td>
		  						<td class="tbtit" width="50">Stato</td>
		  						<td class="tbtit" align="center">Azioni</td>
		  					</tr>';
		  	if($rs->RecordCount() > 0) {
		  	    while(!$rs->EOF) {
		  	    	$content .= '<tr>
		  	    		<td>'.$rs->Fields("nome").'</td>
		  	    		<td>'.$rs->Fields("stato").'</td>
		  	    		<td align="center">
		  	    			<a href="user.php?op=mod&id='.$rs->Fields("id").'"><img src="imgs/ico_edit.gif" alt="modifica" width=16 height=16 title="modifica" border="0"></a>&nbsp;&nbsp;
                  <a href="user.php?op=delete&id='.$rs->Fields("id").'" onclick="return confirm(\'Sei sicuro di voler eliminare questo utente?\')"><img src="imgs/ico_delete.gif" width=16 height=16 alt="cancella" title="cancella" border="0"></a>
		  	    		</td>
		  	    	</tr>';
		  	    	$rs->MoveNext();
		  	    }
		  		$rs->Close();	
		  	}
		  	$content .= '</table>';
			break;
			
		  case "add":
		  	$content = "<table width=300 cellpadding=2 cellspacing=0 class=content>
		   				<tr><td width=100% class=tbtit align=center colspan=2>Nuovo Utente</td></tr>
						 <form name=userform action=\"user.php?op=save\" method=POST>
						  <tr><td class=content>nome:</td><td align=left><input type=text size=30 name=nome></td></tr>
						  <tr><td class=content>username:</td><td align=left><input type=text size=30 name=username></td></tr>
						  <tr><td class=content>password:</td><td align=left><input type=password size=30 name=password></td></tr>
						  <tr><td class=content>livello:</td><td class=content><select name=\"stato\">
						  	<option value=\"admin\">Amministratore</option>
						  	<option value=\"user\">Utente</option>
						  	<option value=\"ci\">Commerciale Italia</option>
						  	<option value=\"ce\">Commerciale Estero</option>
						  </select></td></tr>
						  <tr><td colspan=2><input type=hidden name=op value=\"save\">
		 <input type=image src=\"imgs/ico_save.gif\" title=Salva width=16 height=16>&nbsp;&nbsp;<a class=content href=\"javascript:document.userform.submit();\">Salva</a></td></tr>
						 </form>
						</table>";
		  break;
		  
		  case "save":
		  	$error = user::save($nomep,$usernamep,$statop,$passwordp);
			if($error == "0")
				 $content = "<table width=100% cellpadding=5 cellspacing=0 class=content>
				 				<tr>
								 <td class=error width=100%>Utente inserito con successo!</td>
								</tr>
				 				</table>";
				else  {
				  $content = $error;
				}
		  	break;
		  	
		  case "mod":
		  	$id = $_GET['id'];
		  	$newUser = new user($id);
		   $content = "<table width=300 cellpadding=2 cellspacing=0 class=content>
		   				<tr><td width=100% class=tbtit align=center colspan=2>Modifica i tuoi dati</td></tr>
						 <form name=userform action=\"user.php?op=update\" method=POST>
						  <tr><td class=content>nome:</td><td align=left><input type=text size=30 name=nome value=$newUser->nome></td></tr>
						  <tr><td class=content>username:</td><td align=left><input type=text size=30 name=username value=$newUser->username></td></tr>
						  <tr><td class=content>password:</td><td align=left><input type=password size=30 name=password></td></tr>
						  <tr><td>&nbsp;</td><td class=content>(Lascia vuoto se non vuoi cambiare)</td></tr>
						  <tr><td class=content>livello:</td><td class=content><select name=\"stato\">
						  	<option value=\"admin\"";if($newUser->stato=="admin") $content.= " selected"; $content.=">Amministratore</option>
						  	<option value=\"user\"";if($newUser->stato=="user") $content.= " selected"; $content.=">Utente</option>
						  	<option value=\"ci\"";if($newUser->stato=="ci") $content.= " selected"; $content.=">Commerciale Italia</option>
						  	<option value=\"ce\"";if($newUser->stato=="ce") $content.= " selected"; $content.=">Commerciale Estero</option>
						  </select></td></tr>
						  <tr><td colspan=2><input type=hidden name=op value=\"update\">
						  <input type=hidden name=id value=\"$id\">
		 <input type=image src=\"imgs/ico_save.gif\" title=Salva width=16 height=16>&nbsp;&nbsp;<a class=content href=\"javascript:document.userform.submit();\">Salva</a></td></tr>
						 </form>
						</table>";
		  	break;
		  
		  case "update":
		   $id = $_POST['id'];	
		   $newUser = new user($id);
		   $error = $newUser->update($nomep,$usernamep,$statop,$passwordp);
				if($error == "0")
				 $content = "<table width=100% cellpadding=5 cellspacing=0 class=content>
				 				<tr>
								 <td class=error width=100%>Dati aggiornati con successo! Le modifiche avranno validit� a partire dal prossimo accesso.</td>
								</tr>
				 				</table>";
				else  {
				  $content = $error;
				} 
		  break;
		  
		  case "delete":
		  	$id = $_GET['id'];
		  	$newUser = new user($id);
		  	$error = $newUser->delete();
			if($error == "0")
				 $content = "<table width=100% cellpadding=5 cellspacing=0 class=content>
				 				<tr>
								 <td class=error width=100%>Utente eliminato con successo!</td>
								</tr>
				 				</table>";
				else  {
				  $content = $error;
				}
		  	break;
		  
		  default:
		   $newUser = new user($id_user);
		   $content = "<table width=300 cellpadding=2 cellspacing=0 class=content>
		   				<tr><td width=100% class=tbtit align=center colspan=2>Modifica i tuoi dati</td></tr>
						 <form name=userform action=\"user.php?op=update\" method=POST>
						  <tr><td class=content>nome:</td><td align=left><input type=text size=30 name=nome value=$newUser->nome></td></tr>
						  <tr><td class=content>username:</td><td align=left><input type=text size=30 name=username value=$newUser->username></td></tr>
						  <tr><td class=content>password:</td><td align=left><input type=password size=30 name=password></td></tr>
						  <tr><td>&nbsp;</td><td class=content>(Lascia vuoto se non vuoi cambiare)</td></tr>
						  <tr><td class=content>livello:</td><td class=content><select name=\"stato\">
						  	<option value=\"admin\"";if($newUser->stato=="admin") $content.= " selected"; $content.=">Amministratore</option>
						  	<option value=\"user\"";if($newUser->stato=="user") $content.= " selected"; $content.=">Utente</option>
						  	<option value=\"ci\"";if($newUser->stato=="ci") $content.= " selected"; $content.=">Commerciale Italia</option>
						  	<option value=\"ce\"";if($newUser->stato=="ce") $content.= " selected"; $content.=">Commerciale Estero</option>
						  </select></td></tr>
						  <tr><td colspan=2><input type=hidden name=op value=\"update\">
						  <input type=hidden name=id value=\"$id_user\">
		 <input type=image src=\"imgs/ico_save.gif\" title=Salva width=16 height=16>&nbsp;&nbsp;<a class=content href=\"javascript:document.userform.submit();\">Salva</a></td></tr>
						 </form>
						</table>";
		  break;
		}
	} else {
		$content = printError("Non sei autorizzato ad entrare in questa sezione");
	}	 
       break;

       case AUTH_NOT_LOGGED:
        header("Location:index.html");
		die();
       break;
}
?>
<html><!-- InstanceBegin template="/Templates/moduli.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Modulo Utente</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<link href="style/style.css" rel="stylesheet" type="text/css">
<script type="text/JavaScript">
<!--
<?=$javascript?>

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  var dis;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) {
	   obj=obj.style; 
	   if(v == 'show')  {
	     v = 'visible';
		 dis = 'block';
	   }
	   if(v == 'hide')  {
	     v = 'hidden';
		 dis = 'none';	 
	   }
	 }  
    obj.visibility = v; 
	obj.display = dis;
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('imgs/icons/pag_web-b.gif','imgs/icons/info_utente-b.gif','imgs/icons/prodotti-b.gif','imgs/icons/newsletter-b.gif','imgs/icons/news-b.gif','imgs/icons/gest_banner-b.gif','imgs/icons/utenti-b.gif','imgs/icons/configurazione-b.gif','imgs/icons/kw-b.gif'); <?=$onload?>">
<!-- ImageReady Slices (gestione.psd - Slices: 02, 03, 04, 06, 07, 08, 09, 10, 11, 12) -->
<!-- End ImageReady Slices -->
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="40" height="177" background="imgs/bkgSx.gif">&nbsp;</td>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="552" background="imgs/gestione_02.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="360"><img src="imgs/spacer20.gif" width="360" height="73"></td>
            <td><table width="100%" height="73" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td height="5"><img src="imgs/spacer20.gif" width="45" height="5"></td>
              </tr>
              <tr>
                <td align="left" valign="middle" class="tit01"><!-- InstanceBeginEditable name="user" --><?=$username?><!-- InstanceEndEditable --></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
        <td background="imgs/gestione_03.gif">&nbsp;</td>
        <td width="221"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><img src="imgs/gestione_04.gif" width="221" height="17" alt=""></td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="57"><a href="gestione.php?logout=1"><img src="imgs/gestione_06.gif" alt="Logout" width="57" height="51" border="0"></a></td>
                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><a href="mailto:info@media-tek.it"><img src="imgs/gestione_07.gif" alt="" width="164" height="25" border="0"></a></td>
                  </tr>
                  <tr>
                    <td><a href="#"><img src="imgs/gestione_08.gif" alt="" width="164" height="26" border="0"></a></td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td><img src="imgs/gestione_09.gif" width="221" height="5" alt=""></td>
          </tr>
        </table></td>
      </tr>
    </table>
      <table width="100%" height="104" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="678" background="imgs/gestione_10.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="203"><table width="203" height="104" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td><img src="imgs/spacer20.gif" width="203" height="65"></td>
                </tr>
                <tr>
                  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="45"><img src="imgs/spacer20.gif" width="45" height="39"></td>
                      <td><table width="100%" height="39" border="0" cellpadding="5" cellspacing="0">
                        <tr>
                          <td align="left" valign="middle" class="module"><!-- InstanceBeginEditable name="module" --><?=$module?><!-- InstanceEndEditable --></td>
                        </tr>
                      </table></td>
                    </tr>
                  </table></td>
                </tr>
              </table></td>
              <td><table width="475" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="50"><img src="imgs/spacer20.gif" width="50" height="104" alt=""></td>
                  <td align="left" valign="bottom">
				  <? if($level!="VBL")  { ?>
				  <table border="0" cellspacing="0" cellpadding="2"><tr><?
	if($level=="admin")  {
?><td width="58"><a href="gestione.php?module=content" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('pages','','imgs/icons/pag_web-b.gif',1)"><img src="imgs/icons/pag_web.gif" alt="Pagine web" name="pages" width="58" height="69" border="0"></a></td><td width="58"><a href="gestione.php?module=newsletter" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Newsletter','','imgs/icons/newsletter-b.gif',1)"><img src="imgs/icons/newsletter.gif" alt="Newsletter" name="Newsletter" width="58" height="69" border="0"></a></td><?
	}
	if($level=="admin")  {
?><td width="58"><a href="gestione.php?module=banner" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('banner','','imgs/icons/gest_banner-b.gif',1)"><img src="imgs/icons/gest_banner.gif" alt="Gestione Banner" name="banner" width="58" height="69" border="0"></a></td><?
	}
?><td width="58"><a href="gestione.php?module=prodotti"><img src="imgs/icons/prodotti.gif" alt="Pagine Web" name="pagine" width="58" height="69" border="0" id="pagine" onMouseOver="MM_swapImage('pagine','','imgs/icons/prodotti-b.gif',1)" onMouseOut="MM_swapImgRestore()"></a></td>
</tr></table>
<? } ?>
</td>
				</tr>
              </table></td>
            </tr>
          </table></td>
          <td valign="bottom" background="imgs/gestione_11.gif"><?
	if($level=="admin")  {
?><table cellpadding="2" cellspacing="0">
		    <tr>
			  <td width="58"><a href="gestione.php?module=webuser" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('webutente','','imgs/icons/utenti-b.gif',1)"><img src="imgs/icons/utenti.gif" name="webutente" width="58" height="69" border="0"></a></td>
			  <td width="58"><a href="gestione.php?module=user" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Utente','','imgs/icons/info_utente-b.gif',1)"><img src="imgs/icons/info_utente.gif" name="Utente" width="58" height="69" border="0"></a></td>
			  <td width="20" valign="middle">
			   </td>			  
			</tr>
		   </table><?
		   } else {
?>&nbsp;<?
}
		   ?></td>
          <td width="95"><img src="imgs/gestione_12.gif" width="95" height="104" alt=""></td>
        </tr>
      </table>
    </td>
    <td width="40" background="imgs/bkgDx.gif">&nbsp;</td>
  </tr>
  <tr>
    <td background="imgs/bkgSx.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F6F6F6"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="203" align="left" valign="top" bgcolor="#DFDFDF" class="menusx"><!-- InstanceBeginEditable name="menuSx" --><?=$menusx?><!-- InstanceEndEditable --></td>
        <td align="left" valign="top" bgcolor="#EFEFEF" class="content"><!-- InstanceBeginEditable name="content" --><?=$content?><!-- InstanceEndEditable --></td>
      </tr>
    </table>
      <table width="100%" height="50" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td background="imgs/gestione_03.gif" bgcolor="#F6F6F6" class="copy"><p>2006&copy; Gestione moduli dinamici - release 1.2 - Powered by Media-tek </p></td>
        </tr>
      </table></td>
    <td background="imgs/bkgDx.gif">&nbsp;</td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>